/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package components.shape;

import PCR.MainFrame;
import graphics.GraphicsEngin;
import java.awt.Color;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.SwingUtilities;

/**
 *
 * @author icdev
 */
public class ShapeMouseMotionAction implements MouseMotionListener {

    MainFrame frm = (MainFrame) java.awt.Window.getWindows()[0];

    @Override
    public void mouseDragged(MouseEvent e) {
        Shape curBand = (Shape) e.getSource();
        if (curBand.isMovable()) {
            PointerInfo a = MouseInfo.getPointerInfo();
            Point pt = a.getLocation();
            SwingUtilities.convertPointFromScreen(pt, frm.getSelectedWorkArea().getBandsPanel());
            if (pt.y - curBand.getSize().height / 2 >= 0 && pt.y + curBand.getSize().height / 2 <= frm.getSelectedWorkArea().getBandsPanel().getSize().height) {
                curBand.setLocation(curBand.getLocation().x, pt.y- curBand.getSize().height / 2);
                curBand.setToolTipText("[Y: " + Integer.toString((frm.getSelectedWorkArea().getBandsPanel().getHeight()-pt.y) - curBand.getSize().height / 2) + "]");
                curBand.getTipText().setVisible(true);
                curBand.getTipText().setLocation(curBand.getLocation().x + curBand.getSize().width, pt.y - curBand.getSize().height + 20);
                curBand.getTipText().setTipText("[Y: " + Integer.toString((frm.getSelectedWorkArea().getBandsPanel().getHeight()-pt.y) - curBand.getSize().height / 2) + "]");
                Color workSpaceBGColor = frm.getSelectedWorkArea().getBackground();
                Color textColor = GraphicsEngin.getComplementaryColor(workSpaceBGColor);
                curBand.getTipText().setForeground(textColor);
                frm.getSelectedWorkArea().getBandsPanel().getShapeMasure().setLocation(0, curBand.getLocation().y+curBand.getSize().height/2);
                frm.getSelectedWorkArea().getBandsPanel().getShapeMasure().setWidth(curBand.getLocation().x);
                frm.getSelectedWorkArea().getBandsPanel().getShapeMasure().setVisible(true);
                
                frm.setBandYPosition(Integer.toString((frm.getSelectedWorkArea().getBandsPanel().getHeight()-pt.y) - curBand.getSize().height / 2));
                frm.getSelectedWorkArea().setSaved(false);

            }
        }
    }

    @Override
    public void mouseMoved(MouseEvent e) {
    }
}
